package com.eeepay.eeepay_v2.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.eeepay.eeepay_v2.R;
import com.eeepay.eeepay_v2.util.Constant;
import com.eeepay.eeepay_v2.util.DBUtils;
import com.eeepay.v2_library.adapter.ABBaseAdapter;
import com.eeepay.v2_library.adapter.ABViewHolder;
import com.eeepay.v2_library.log.LogUtils;
import com.eeepay.v2_library.view.RoundAngleImageView;

import java.util.Map;

/**
 * Created by zw on 2016/3/22 0022.
 */
public class NewsListAdapter extends ABBaseAdapter<Map<String, String>> {
    private final static String IS_TOP = "top";//消息是否置顶

    public NewsListAdapter(Context context) {
        super(context);
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_news_center_list;
    }

    @Override
    public void convert(ABViewHolder holder, Map<String, String> model) {

        if (DBUtils.query(model.get(Constant.USER_ID), model.get(Constant.NEWS_ID))) {
            LogUtils.d("TAG", "未读 ：" + model.get(Constant.NEWS_TITLE));
//            holder.getView(R.id.iv_left).setBackgroundColor(mContext.getResources().getColor(R.color.red));
            holder.setTextColor(R.id.tv_content, mContext.getResources().getColor(R.color.gray_txt_color_1));
        } else {
            LogUtils.d("TAG", "已读 ：" + model.get(Constant.NEWS_TITLE));
//            holder.getView(R.id.iv_left).setBackgroundColor(mContext.getResources().getColor(R.color.white));
            holder.setTextColor(R.id.tv_content, mContext.getResources().getColor(R.color.gray_txt_color_3));
        }
        String img = model.get(Constant.MESSAGE_IMG);
        RoundAngleImageView iv = holder.getView(R.id.iv_left);
        if (TextUtils.isEmpty(img)) {
            iv.setVisibility(View.GONE);
        } else {
            iv.setVisibility(View.VISIBLE);
            holder.setImageByUrl(R.id.iv_left, model.get(Constant.MESSAGE_IMG));
        }
        holder.setText(R.id.tv_content,model.get(Constant.NEWS_TITLE));//
        holder.setText(R.id.tv_time, model.get(Constant.CREATE_TIME));
        //add by zhuangzeqin 2017年10月20日10:14:03 判断是否为置顶公告 如果是置顶公告则为Y 否则是N
        String isTop = model.get(IS_TOP);
        ImageView iv_zd = holder.getView(R.id.zd);
        if (TextUtils.equals(isTop, "Y")) {
            iv_zd.setVisibility(View.VISIBLE);
        } else {
            iv_zd.setVisibility(View.GONE);
        }
    }
}
